/*
   @Copyright:LintCode
   @Author:   tjyemail
   @Problem:  http://www.lintcode.com/problem/clone-binary-tree
   @Language: C++
   @Datetime: 16-12-07 07:41
   */

/**
 * Definition of TreeNode:
 * class TreeNode {
 * public:
 *     int val;
 *     TreeNode *left, *right;
 *     TreeNode(int val) {
 *         this->val = val;
 *         this->left = this->right = NULL;
 *     }
 * }
 */
class Solution {
public:
	/**
	 * @param root: The root of binary tree
	 * @return root of new tree
	 */
	TreeNode* cloneTree(TreeNode *root) {
		// Write your code here
		if (!root) return NULL;
		TreeNode *r = new TreeNode(root->val);
		r->left = cloneTree(root->left);
		r->right = cloneTree(root->right);
		return r;
	}
};
